﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using COFE.Core;
using COFE.Core.Utils;

namespace COFE.Core
{
    /// <summary>
    /// Extends IInternalFileSystemInfoExA.
    /// </summary>
    public static class IInternalFileSystemInfoExAExtension
    {

        #region getDirectoryRoot

        public static IInternalDirectoryInfoExA getDirectoryRoot(this IInternalFileSystemInfoExA lookup, bool lookupCurrentItem)
        {
            IInternalDirectoryInfoExA dir = lookupCurrentItem && (lookup is IInternalDirectoryInfoExA) ?
                (IInternalDirectoryInfoExA)lookup : (IInternalDirectoryInfoExA)lookup.Parent;


            while (dir.DirectoryType != DirectoryTypeEnum.dtDesktop &&
                dir.DirectoryType != DirectoryTypeEnum.dtDrive &&
                dir.DirectoryType != DirectoryTypeEnum.dtRoot &&
                dir != null && dir.Parent != null)
                dir = (IInternalDirectoryInfoExA)dir.Parent;

            return dir;
        }

        public static IInternalDirectoryInfoExA getDirectoryRoot(this IInternalFileSystemInfoExA lookup)
        {
            return getDirectoryRoot(lookup, false);
        }


        #endregion

        #region getRelativePath

        public static string getRelativePath(this IInternalFileSystemInfoExA entry, IDirectoryInfo baseDirectory)
        {
            return EntryInternalUtils.GetRelativePath(entry, baseDirectory);
        }

        #endregion

        public static string getParseName(this IInternalFileSystemInfoExA entry)
        {
            return entry.GetProperty(FileSystemInfoProperties.FullParseName).ValueAsString;
        }

    }
}
